% 设置等宽字体用于代码排版
\setmonofont{Iosevka Fixed SS09}

% 设置代码标题引导词
\codeset{pretitle=代码清单}

% 重定义强调字体的代码，解决默认强调字体是italic，此时中文会用楷体代替，
% 在此设置为加粗，注意需要使用etoolbox宏包
\makeatletter
\let\origemph\emph
\newcommand*\emphfont{\normalfont\bfseries}
\DeclareTextFontCommand\@textemph{\emphfont}
\newcommand\textem[1]{%
  \ifdefstrequal{\f@series}{\bfdefault}
    {\@textemph{\CTEXunderline{#1}}}
    {\@textemph{#1}}%
}
\RenewDocumentCommand\emph{s o m}{%
  \IfBooleanTF{#1}
    {\textem{#3}}
    {\IfNoValueTF{#2}
      {\textem{#3}\index{#3}}
      {\textem{#3}\index{#2}}%
     }%
}
\makeatother

% 设置插图路径
\graphicspath{{figures/},{figs/}}

% 定义提醒字体
\newcommand{\alert}[1]{\textcolor{red}{\textbf{#1}}}

% 载入TikZ库
\usetikzlibrary{calc,tikzmark}
% \usetikzlibrary{decorations.pathreplacing}
% \usetikzlibrary{arrows,positioning,shapes,shadows}
% \usetikzlibrary {arrows.meta}

% ========csquotes宏包的中文引号样式==========
% Unicode引号样式
\DeclareQuoteStyle{ucstyle}% style name
    {\symbol{"201C}}% opening outer mark
    {\symbol{"201D}}% closing outer mark
    {\symbol{"2018}}% opening inner mark
    {\symbol{"2019}}% closing inner mark
% 传统中文样式
\DeclareQuoteStyle{cnzhstyle}% style name
    {\symbol{"300E}}% opening outer mark
    {\symbol{"300F}}% closing outer mark
    {\symbol{"300C}}% opening inner mark
    {\symbol{"300D}}% closing inner mark
% 反转传统中文样式
\DeclareQuoteStyle{zhcnstyle}% style name
    {\symbol{"300C}}% opening outer mark
    {\symbol{"300D}}% closing outer mark
    {\symbol{"300E}}% opening inner mark
    {\symbol{"300F}}% closing inner mark
% 书名号样式
\DeclareQuoteStyle{zhtitlestyle}% style name
    {\symbol{"300A}}% opening outer mark
    {\symbol{"300B}}% closing outer mark
    {\symbol{"3008}}% opening inner mark
    {\symbol{"3009}}% closing inner mark
% 选择样式
\setquotestyle{ucstyle}
% =================================================================

% ========minted宏包C语言代码排版参数和自定义命令==========
% \usemintedstyle{bw}
\usemintedstyle{default}
\setminted{fontsize=\small, breakautoindent=false}
\newmintinline{c}{autogobble, fontsize=\normalsize}
\newmintinline[cinlinett]{c}{autogobble, fontsize=\normalsize, escapeinside=||}
\newmintinline[cinttsml]{c}{autogobble, fontsize=\small, escapeinside=||}
\newmintinline[cinttscr]{c}{autogobble, fontsize=\scriptsize, escapeinside=||}
\newmintinline[cinttfts]{c}{autogobble, fontsize=\footnotesize, escapeinside=||}
\newmintinline[cintttny]{c}{autogobble, fontsize=\tiny, escapeinside=||}
\newmintinline[cintt]{c}{autogobble,escapeinside=||, fontsize=\normalsize}
\newminted{c}{autogobble, fontsize=\small, bgcolor=yellow!20!white, frame=lines}
\newminted[ctt]{c}{autogobble,escapeinside=||}%, frame=lines
\newminted[ctxt]{c}{autogobble, fontsize=\normalsize, escapeinside=||}%, frame=lines
\newmintedfile{c}{linenos=true}
% ===================================================

% ========minted宏包shell脚本语言代码排版参数和自定义命令==========
\newmintinline{shell}{autogobble,fontsize=\normalsize}
\newminted[shell]{sh}{autogobble,fontsize=\small, bgcolor=yellow!20!white, frame=lines}
% ===================================================

% ========minted宏包makefile代码排版参数和自定义命令==========
\newmintinline{basemake}{autogobble,fontsize=\normalsize}
\newmintinline[makefileinline]{basemake}{autogobble,fontsize=\normalsize,escapeinside=!!}
\newminted{basemake}{autogobble,fontsize=\small}
\newminted[makefilett]{basemake}{autogobble,bgcolor=yellow!20!white,mathescape,
  fontsize=\small,escapeinside=!!, frame=lines}
\newmintedfile{basemake}{bgcolor=yellow!20!white,mathescape,
  linenos=true, frame=lines}
% ===================================================

% 自定义垂直省略号
\makeatletter
\DeclareRobustCommand{\rvdots}{%
  \vbox{
    \baselineskip4\p@\lineskiplimit\z@
    \kern-\p@
    \hbox{.}\hbox{.}\hbox{.}
  }}
\makeatother

% 调整居中环境前后距离
\let\oldcenter\center
\let\oldendcenter\endcenter
\renewenvironment{center}{\setlength\topsep{0pt}\oldcenter}{\oldendcenter\setlength\topsep{0pt}}

% ===========设置引用标记名称============
\def\equationautorefname~#1\null{公式(#1)\null}%
\def\footnoteautorefname{脚注}%
\def\itemautorefname~#1\null{第#1项\null}%
\def\figureautorefname{图}%
\def\tableautorefname{表}%
\def\appendixautorefname{附录}%
\def\chapterautorefname~#1\null{第#1章\null}%
\def\sectionautorefname~#1\null{第#1节\null}%
\def\sectionautorefname~#1\null{第#1节\null}%
\def\subsectionautorefname~#1\null{第#1小节\null}%
\def\subsubsectionautorefname~#1\null{第#1小小节\null}%
\def\paragraphautorefname~#1\null{第#1段\null}%
\def\subparagraphautorefname~#1\null{第#1小段\null}%
\def\theoremautorefname{定理}%
\def\pageautorefname~#1\null{第#1页\null}%

% 代码交叉引用
\counterwithin{cvcounter}{chapter}
\renewcommand{\thecvcounter}{\thechapter.\arabic{cvcounter}}
\def\cvcounterautorefname~#1\null{代码#1\null}%

% 设置公式前后距离
%\setlength{\belowdisplayskip}{0pt} 
%\setlength{\belowdisplayshortskip}{0pt}
%\setlength{\abovedisplayskip}{0pt}
%\setlength{\abovedisplayshortskip}{0pt}
\AtBeginDocument{%
  \addtolength\abovedisplayskip{0.5\baselineskip}%
  \addtolength\belowdisplayskip{0.5\baselineskip}%
  \addtolength\abovedisplayshortskip{0.5\baselineskip}%
  \addtolength\belowdisplayshortskip{0.5\baselineskip}%
}

% URL断行处理

% \makeatletter
% \def\urlalphabet{%
%       \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
%       \do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
%       \do\u\do\v\do\w\do\x\do\y\do\z\do\a\do\b\do\c\do\d%
%       \do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n%
%       \do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x%
%       \do\y\do\z}
% \def\urldigits{\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\0}
% \g@addto@macro{\urlbreaks}{\urlords}
% \g@addto@macro{\urlbreaks}{\urlalphabet}
% \g@addto@macro{\urlbreaks}{\urldigits}
% \makeatother

\renewcommand{\notename}{注意:}

% \NiceMatrixOptions{cell-space-top-limit=3pt,cell-space-bottom-limit=3pt}

% ==================设置列表环境的格式==============
% 将列表的列表项缩进方式改为首行缩进的中文格式
\newcounter{descriptcount}
\renewcommand*\thedescriptcount{(\arabic{descriptcount})}
\setlist[description]{
    topsep=0pt,
    itemsep=0pt,
    partopsep=0pt,
    parsep=\parskip,
    labelindent=\parindent,
    labelwidth=1.3em,
    labelsep = .3em,
    itemindent=3.6em,
    leftmargin=!,
    before={\setcounter{descriptcount}{0}},%
    font=\normalfont\stepcounter{descriptcount}\thedescriptcount~,
    %font=\normalfont,
}

\setlist[enumerate]{
    label=(\arabic*),
    topsep=0pt,
    itemsep=0pt,
    partopsep=0pt,
    parsep=\parskip,
    labelindent=\parindent,
    labelwidth=1.3em,
    labelsep = .3em,
    itemindent=3.6em,
    leftmargin=!,
}
\setlist[itemize]{
    topsep=0pt,
    itemsep=0pt,
    partopsep=0pt,
    parsep=\parskip,
    labelindent=1.4em,
    labelwidth=1.3em,
    labelsep = .3em,
    itemindent=3em,
    leftmargin=!,
}
% ================================================
